package com.cloud.exceptions;

import com.cloud.rest.BaseEnumError;

import static com.cloud.rest.EnumGlobalError.SYSTEM_ERROR;

/**
 * @ClassName: BusinessException
 * @Description: 业务异常类
 * @Version: v1.0.0
 * @Author: yangyuwei
 * @Date: 2020/9/3
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2020/9/3      yangyuwei      v1.0.0      创建
 */
public class RpcException extends BaseRuntimeException {

    public static RpcException build(String code, String msg) {
        RpcException rpcException = new RpcException();
        rpcException.setCode(code);
        rpcException.setMsg(msg);
        return rpcException;
    }

    public static RpcException build(BaseEnumError error) {
        return new RpcException(error);
    }

    public static RpcException build(BaseEnumError error, Throwable cause) {
        return new RpcException(error, cause);
    }

    public RpcException() {
        this(SYSTEM_ERROR, null);
    }

    public RpcException(BaseEnumError error) {
        this(error, null);
    }

    public RpcException(BaseEnumError error, Throwable cause) {
        super(error, cause);
    }

    public static ReqParamException build(String msg) {
        return new ReqParamException(new BaseEnumError() {
            @Override
            public String getCode() {
                return "0002";
            }

            @Override
            public String getMsg() {
                return msg;
            }

            @Override
            public String getDetail() {
                return null;
            }
        }, null);
    }
}
